package main

import "fmt"

//一次遍历:4ms 84%,2.9MB 100%
func maxProfit(prices []int) int {
	if len(prices) < 2 {
		return 0
	}
	minPrice := prices[0]
	maxProfit := 0
	for i := 1; i < len(prices); i++ {
		minPrice = min(prices[i], minPrice)
		maxProfit = max(maxProfit, prices[i]-minPrice)
	}
	return maxProfit
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func main() {
	fmt.Println(maxProfit([]int{}))
}
